/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.view;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import model.Anggota;
import model.Perpustakaan;

/**
 *
 * @author Litha
 */
public class PanelTambahAnggota extends JPanel {
    private JLabel labelKodeAnggota;
    private JTextField textKodeAnggota;
    private JLabel labelNama;
    private JTextField textNama;
    private JButton tombolSimpan;
    private JButton tombolBatal;
    
    public PanelTambahAnggota() {
        this.setLayout(null);
        this.setSize(600, 700);
                
    JLabel lab1 = new JLabel("TAMBAH ANGGOTA :");
        lab1.setBounds(100,30,200,20);
        this.add(lab1);
        
        //label KodeAnggota
       
        labelKodeAnggota = new JLabel ("Kode Anggota");
        labelKodeAnggota.setBounds(65, 85, 90, 20);
        this.add(labelKodeAnggota);
        
        textKodeAnggota = new JTextField ("");
        textKodeAnggota.setBounds(200, 85, 150, 20);
        this.add(textKodeAnggota);
        
         //label Nama
        
        labelNama = new JLabel ("Nama");
        labelNama.setBounds(65 ,120 , 90 , 20);
        this.add(labelNama);
        
        textNama = new JTextField ("");
        textNama.setBounds(200, 120, 150, 20);
        this.add(textNama);
        
        //tombol simpan & batal
        
        tombolSimpan = new JButton ("Simpan");
        tombolSimpan.setBounds(100 , 260 , 80 , 20);
        this.add(tombolSimpan);
        tombolSimpan.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    tombolSimpanAction();
                } catch (Exception ex) {
                    Logger.getLogger(PanelTambahAnggota.class.getName()).log(Level.SEVERE, null, ex);
                }
                
               
            }
        }
                );
        tombolBatal = new JButton ("Batal");
        tombolBatal.setBounds(250 , 260 , 80 , 20);
        this.add(tombolBatal);
        
                
                
    }
    private void tombolSimpanAction() throws Exception {
        Anggota anggota = new Anggota();
        anggota.setNama(textNama.getText());
        anggota.setId(textKodeAnggota.getText());
        Perpustakaan.tambahAnggota(anggota);
        JOptionPane.showMessageDialog(this , "anggota");
    }
    
    
    public static void main(String[] args) {
       JDialog f = new JDialog();
        //JFrame f = new JFrame();
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        f.setLayout(new FlowLayout());
        f.setSize(500, 400);
        f.getContentPane().add(new PanelTambahAnggota());
        f.setVisible(true);
}}

